home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / SLIDER.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  241 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. // Definition of classes TSlider & TVSlider.  This defines the basic behavior
  8. // of slider controls.
  9. //----------------------------------------------------------------------------
  10. #if !defined(OWL_SLIDER_H)
  11. #define OWL_SLIDER_H
  12.  
  13. #if !defined(OWL_SCROLLBA_H)
  14. # include <owl/scrollba.h>
  15. #endif
  16. #if !defined(WINSYS_COLOR_H)
  17. # include <winsys/color.h>
  18. #endif
  19. #if !defined(OWL_COMMCTRL_H)
  20. # include <owl/commctrl.h>
  21. #endif
  22. #include <owl/slider.rh>
  23.  
  24. #if defined(BI_NAMESPACE)
  25. namespace OWL {
  26. #endif
  27.  
  28. // Generic definitions/compiler options (eg. alignment) preceeding the
  29. // definition of classes
  30. #include <services/preclass.h>
  31.  
  32. class _OWLCLASS TDC;
  33. class _OWLCLASS TRegion;
  34. class _OWLCLASS TBrush;
  35.  
  36. //
  37. // class TSlider
  38. // ~~~~~ ~~~~~~~
  39. class _OWLCLASS TSlider : public TScrollBar {
  40.   public:
  41.     // Constructors and destructor
  42.     //
  43.     TSlider(TWindow*        parent,
  44.             int             id,
  45.             int x, int y, int w, int h,
  46.             TResId          thumbResId,
  47.             TModule*        module = 0);
  48.     TSlider(TWindow* parent, int resId, TResId thumbResId, TModule* module = 0);
  49.    ~TSlider();
  50.  
  51.     // Overload TScrollBar virtual functions
  52.     //
  53.     void          GetRange(int& min, int& max) const;
  54.     int           GetPosition() const;
  55.     void          SetRange(int min, int max, bool redraw = true);
  56.     void          SetPosition(int thumbPos);
  57.     void          SetPosition(int thumbPos, bool redraw);
  58.  
  59.     // New settings introduced by sliders sliders
  60.     //
  61.     void          SetRuler(int ticGap, bool snap = false);
  62.     void          SetRuler(int tics[], int ticCount, bool snap = false);
  63.     void          SetSel(int start, int end, bool redraw = true);
  64.     void          GetSel(int& start, int& end);
  65.  
  66.     static void   SetNativeUse(TNativeUse nu);
  67.  
  68.   protected:
  69.  
  70.     // Override TWindow virtual member functions
  71.     //
  72.     char far*      GetClassName();
  73.     void           SetupWindow();
  74.  
  75.     int            SnapPos(int pos);
  76.  
  77.     // OWL's slider implementation
  78.     //
  79. #if !defined(OWL_NATIVECTRL_ALWAYS)
  80.  
  81.     // TSlider virtual functions for implementation
  82.     //
  83.     virtual int    PointToPos(const TPoint& point) = 0;  
  84.     virtual TPoint PosToPoint(int pos) = 0;
  85.     virtual void   NotifyParent(int scrollCode, int pos=0) = 0;
  86.  
  87.     virtual void   SetupThumbRgn();
  88.     virtual int    HitTest(TPoint& point) = 0;
  89.     virtual void   SlideThumb(TDC& dc, int thumbPos);
  90.  
  91.     virtual void   PaintRuler(TDC& dc) = 0;
  92.     virtual void   PaintSlot(TDC& dc) = 0;
  93.     virtual void   PaintThumb(TDC& dc);
  94.  
  95.     void           GetBkColor(TDC& dc);
  96.  
  97.     // Message response functions
  98.     //
  99.     uint          EvGetDlgCode(MSG far*);
  100.     void          EvPaint();
  101.     void          EvLButtonDown(uint modKeys, TPoint& point);
  102.     void          EvMouseMove(uint modKeys, TPoint& point);
  103.     void          EvLButtonUp(uint modKeys, TPoint& point);
  104.     void          EvLButtonDblClk(uint modKeys, TPoint& point);
  105.     void          EvKeyDown(uint key, uint repeatCount, uint flags);
  106.     void          EvSetFocus(HWND hWndLostFocus);
  107.     void          EvKillFocus(HWND hWndGetFocus);
  108. #endif
  109.  
  110.   protected_data:
  111.     int           Min;        // Minimum position value
  112.     int           Max;        // Maximum position value
  113.     uint          Range;      // Positive range
  114.     int           Pos;        // Current position value
  115.     TResId        ThumbResId; // Bitmap res id for thumb knob
  116.     TRect         ThumbRect;  // Bounding rect of Thumb in pixels
  117.     TRegion*      ThumbRgn;   // Optional clipping/hit test region
  118.     TRect         CaretRect;  // Bounding rect of Thumb's blink caret
  119.     int           SlotThick;  // Thickness(width or height) of slot
  120.     int           TicGap;     // Gap between tics in pos units
  121.     int*          Tics;       // Or array of specific tics
  122.     int           TicCount;   //  and its size
  123.     bool          Snap;       // Snap Thumb to tics
  124.     int           SelStart;   // Selection start & end
  125.     int           SelEnd;
  126.  
  127.     bool          Sliding;
  128.     TColor        BkColor;    // Color to use to paint background
  129.  
  130.     static TNativeUse ClassNativeUse;  // Default use of native control impl
  131.  
  132.     // Statics used while the mouse is down & Thumb is sliding
  133.     //
  134.     static TSize  MouseOffset;
  135.     static TDC*   SlideDC;
  136.  
  137.   DECLARE_RESPONSE_TABLE(TSlider);
  138.   DECLARE_ABSTRACT_STREAMABLE(_OWLCLASS, TSlider, 2);
  139. };
  140.  
  141. //
  142. // class THSlider
  143. // ~~~~~ ~~~~~~~~
  144. class _OWLCLASS THSlider : public TSlider {
  145.   public:
  146.     THSlider(TWindow*        parent,
  147.              int             id,
  148.              int x, int y, int w, int h,
  149.              TResId          thumbResId = IDB_HSLIDERTHUMB,
  150.              TModule*        module = 0);
  151.     THSlider(TWindow* parent, int resId, TResId thumbResId = IDB_HSLIDERTHUMB,
  152.              TModule* module = 0);
  153.  
  154.   protected:
  155. #if !defined(OWL_NATIVECTRL_ALWAYS)
  156.     // Override TSlider virtual member functions
  157.     //
  158.     int    PointToPos(const TPoint& point);
  159.     TPoint PosToPoint(int pos);
  160.     void   NotifyParent(int scrollCode, int pos=0);
  161.     int    HitTest(TPoint& point);
  162.     void   PaintRuler(TDC& dc);
  163.     void   PaintSlot(TDC& dc);
  164. #endif
  165.  
  166.   private:
  167.     // Hidden to prevent accidental copying or assignment
  168.     //
  169.     THSlider(const THSlider&);
  170.     THSlider& operator =(const THSlider&);
  171.  
  172.   DECLARE_STREAMABLE(_OWLCLASS, THSlider, 1);
  173. };
  174.  
  175. //
  176. // class TVSlider
  177. // ~~~~~ ~~~~~~~~
  178. class _OWLCLASS TVSlider : public TSlider {
  179.   public:
  180.     TVSlider(TWindow*        parent,
  181.              int             id,
  182.              int x, int y, int w, int h,
  183.              TResId          thumbResId = IDB_VSLIDERTHUMB,
  184.              TModule*        module = 0);
  185.     TVSlider(TWindow* parent, int resId, TResId thumbResId = IDB_VSLIDERTHUMB,
  186.              TModule* module = 0);
  187.  
  188.   protected:
  189. #if !defined(OWL_NATIVECTRL_ALWAYS)
  190.     // Override TSlider virtual member functions
  191.     //
  192.     int    PointToPos(const TPoint& point);
  193.     TPoint PosToPoint(int pos);
  194.     void   NotifyParent(int scrollCode, int pos=0);
  195.     int    HitTest(TPoint& point);
  196.     void   PaintRuler(TDC& dc);
  197.     void   PaintSlot(TDC& dc);
  198. #endif
  199.  
  200.   private:
  201.     TVSlider(const TVSlider&);
  202.     TVSlider& operator =(const TVSlider&);
  203.  
  204.   DECLARE_STREAMABLE(_OWLCLASS, TVSlider, 1);
  205. };
  206.  
  207. // Generic definitions/compiler options (eg. alignment) following the
  208. // definition of classes
  209. #include <services/posclass.h>
  210.  
  211. #if defined(BI_NAMESPACE)
  212. } // namespace OWL
  213. #endif
  214.  
  215. //----------------------------------------------------------------------------
  216. // Inline implementations
  217. //
  218.  
  219. //
  220. inline void TSlider::GetRange(int& min, int& max) const
  221. {
  222.   min = Min; max = Max;
  223. }
  224.  
  225. //
  226. inline int TSlider::GetPosition() const
  227. {
  228.   return Pos;
  229. }
  230.  
  231. //
  232. // Specifies whether the class uses the native (operating system) implementation
  233. // or emulates it.
  234. //
  235. inline void TSlider::SetNativeUse(TNativeUse nu)
  236. {
  237.   ClassNativeUse = nu;
  238. }
  239.  
  240. #endif  // OWL_SLIDER_H
  241.